<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>动态显示时间</title>
     
    <style>
         .time
         {
            font-size: 20px;
         }
    </style>

</head>
<body>
   
    <div class="time">00:00:00:00</div>

    <script>
          
          function padLeft(number)
          {
             number+="";
             return number.padStart(2,"0");
          }
          //获取时间div
          var timeEl = document.querySelector(".time");  
          setInterval(function(){
              
          var now = new Date();
          var hour =padLeft( now.getHours());
          var minute = padLeft(now.getMinutes());
          var second =padLeft( now.getSeconds());
        
          var time = `${hour}:${minute}:${second}`
          timeEl.textContent = time;
          },1000)
         
          
        
        
    </script>
</body>
</html>